package com.w3c.pragmatic.domain.req;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 分页对象
 *
 * @author wangdong
 */
@Data
public class PageReq implements Serializable {

  private static final long serialVersionUID = -24261005790906542L;

  @ApiModelProperty(value = "当前页（默认：1）")
  private int current = 1;

  @ApiModelProperty(value = "每页多少行（默认：10）")
  private int size = 3;

  /**
   * 当前页修正
   *
   * @param current 当前页
   */
  public void setCurrent(int current) {
    this.current = Math.max(current, 1);
  }

  /**
   * 当前页大小修正
   *
   * @param size 页大小
   */
  public void setSize(int size) {
    if (size < 1) {
      if (size == -1) {
        // 全量
        this.size = size;
      } else {
        this.size = 3;
      }
    } else {
      this.size = size;
    }
  }
}
